//
//  FGSettingViewController.m
//  Mi6App
//
//  Created by Mr.Lemon on 7/25/13.
//  Copyright (c) 2013 4G Secure. All rights reserved.
//

#import "FGSettingViewController.h"

@interface FGSettingViewController ()
{
    UIPickerView *pickerView;
    UIActionSheet *actionSheet;
    NSMutableArray *arrLanguage;
    NSInteger currentLanguageIndex;
    NSInteger indexPicker;
    
}
@end

@implementation FGSettingViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.viewContainer.layer.borderColor=[UIColor grayColor].CGColor;
    self.viewContainer.layer.cornerRadius=10;
    self.viewContainer.layer.borderWidth=1;
    [self initLanguagePicker];
    
}



-(void)initLanguagePicker{
    
    arrLanguage=[[NSMutableArray alloc] initWithObjects:@"English",@"French", nil];
    UIToolbar* keyboardDoneButtonView = [[UIToolbar alloc] init];
    keyboardDoneButtonView.barStyle = UIBarStyleBlack;
    keyboardDoneButtonView.translucent = YES;
    keyboardDoneButtonView.tintColor = nil;
    [keyboardDoneButtonView sizeToFit];
    UIBarButtonItem* doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done"
                                                                   style:UIBarButtonItemStyleBordered target:self
                                                                  action:@selector(onDoneSelectLanguage)];
    
    [keyboardDoneButtonView setItems:[NSArray arrayWithObjects:doneButton, nil]];
    
    self.lblLanguage.inputAccessoryView = keyboardDoneButtonView;
    
    pickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0,0, 320, 160)];
    pickerView.dataSource = self;
    pickerView.delegate = self;
    pickerView.alpha = 1;
    pickerView.showsSelectionIndicator = YES;
    //Pre select
    [pickerView selectRow:0 inComponent:0 animated:YES];
    
    self.lblLanguage.inputView = pickerView;
}

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
    
    [UIView animateWithDuration:0.4 animations:^{
        
        CGRect frame = self.view.frame;
        frame.origin.y -= 50;
        self.view.frame = frame;
    } completion:^(BOOL finished) {
        
    }];
    return YES;
}
- (void)onDoneSelectLanguage {
    
    [self.lblLanguage resignFirstResponder];
    currentLanguageIndex=indexPicker;
    self.lblLanguage.text=[arrLanguage objectAtIndex:currentLanguageIndex];
    // FGU
    [UIView animateWithDuration:0.4 animations:^{
        
        CGRect frame = self.view.frame;
        frame.origin.y += 50;
        self.view.frame = frame;
    } completion:^(BOOL finished) {
        
    }];
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    DEBUGLog(@"Index : %d",row);
    indexPicker=row;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
    return arrLanguage.count;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
    return [arrLanguage objectAtIndex:row];
}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return 1;
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onSwitchNotificationChange:(id)sender {
    
    if([self.switchNotificationSetting isOn])
    {
        [FGUserDefaultUtil storeBooleanWithKey:kNotification andValue:YES];
    }
    else{
            [FGUserDefaultUtil storeBooleanWithKey:kNotification andValue:YES];
    }
}
- (void)viewDidUnload {
    [self setViewContainer:nil];
    
    [self setLblLanguage:nil];
    [self setSwitchNotificationSetting:nil];
    [self setLblSettingLanguage:nil];
    [self setLblSettingNotification:nil];
    [self setLblSettingLanguage:nil];
    [self setLblSettingTitle:nil];
    [super viewDidUnload];
}
- (IBAction)onNotificationSettingChange:(id)sender {
}
@end
